package com.lineage.server.serverpackets;

import com.lineage.config.ConfigWho;
import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class S_WhoCharinfo extends ServerBasePacket {
  private byte[] _byte;
  
  public S_WhoCharinfo(L1Character cha, ClientExecutor client) {
    this._byte = null;
    String lawfulness = "";
    int lawful = cha.getLawful();
    if (lawful < 0) {
      lawfulness = "($1503)";
    } else if (lawful >= 0 && lawful < 500) {
      lawfulness = "($1502)";
    } else if (lawful >= 500) {
      lawfulness = "($1501)";
    } 
    writeC(71);
    writeH(166);
    writeC(1);
    String title = "";
    String clan = "";
    if (!cha.getTitle().equalsIgnoreCase(""))
      title = String.valueOf(String.valueOf(cha.getTitle())) + " "; 
    String name = "";
    if (cha instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)cha;
      L1PcInstance herotpc = client.getActiveChar();
      if (pc.isPrivateShop()) {
        herotpc.sendPackets(new S_SystemMessage("\\fT挂卖摆摊中"));
        return;
      } 
      String msg = "";
      if (pc.isCrown()) {
        msg = "\\fV王族";
      } else if (pc.isKnight()) {
        msg = "\\fV骑士";
      } else if (pc.isElf()) {
        msg = "\\fV妖精";
      } else if (pc.isWizard()) {
        msg = "\\fV法师";
      } else if (pc.isDarkelf()) {
        msg = "\\fV黑妖";
      } else if (pc.isDragonKnight()) {
        msg = "\\fV龙骑士";
      } else if (pc.isIllusionist()) {
        msg = "\\fV幻术士";
      } 
      name = pc.getName();
      writeS("玩家: " + pc.getName() + "\r\n血盟: " + pc.getClanname() + "　职业: " + msg + " " + lawfulness);
      if (herotpc.isGm()) {
        List<L1ItemInstance> items = pc.getInventory().getItems();
        List<L1ItemInstance> itemsx = new CopyOnWriteArrayList<>();
        Iterator<L1ItemInstance> iterator = items.iterator();
        while (iterator.hasNext()) {
          L1ItemInstance item = iterator.next();
          itemsx.add(item);
        } 
        herotpc.sendPackets(new S_WhoHero(herotpc, 0, itemsx));
        String msg2 = "";
        String msg3 = "";
        String msg4 = "";
        String msg5 = "";
        String msg6 = "";
        String msg7 = "";
        String msg8 = "";
        String msg9 = "";
        String msg10 = "";
        String msg11 = "";
        String msg12 = "";
        int i = pc.getLevel();
        msg3 = String.valueOf(pc.getCurrentHp()) + " / " + pc.getMaxHp();
        msg4 = String.valueOf(pc.getCurrentMp()) + " / " + pc.getMaxMp();
        int j = pc.getAc();
        short s1 = pc.getStr();
        short s2 = pc.getDex();
        short s3 = pc.getInt();
        short s4 = pc.getCon();
        short s5 = pc.getWis();
        short s6 = pc.getCha();
        msg12 = String.valueOf(pc.getMr()) + " %";
        herotpc.sendPackets(new S_SystemMessage("\\fT等级:[" + i + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fW血量:[" + msg3 + "]  //  魔力:[" + msg4 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fU防御:[" + j + "]  //  魔防:[" + msg12 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR力量:[" + s1 + "]  //  敏捷:[" + s2 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR智力:[" + s3 + "]  //  体质:[" + s4 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR精神:[" + s5 + "]  //  魅力:[" + s6 + "]"));
        herotpc.sendPackets(new S_SystemMessage(
              "出生素质  力:" + pc.getOriginalStr() + " 敏:" + pc.getOriginalDex() + " 智:" + pc.getOriginalInt()));
        herotpc.sendPackets(new S_SystemMessage(
              "出生素质  精:" + pc.getOriginalWis() + " 体:" + pc.getOriginalCon() + " 魅:" + pc.getOriginalCha()));
        return;
      } 
      if (ConfigWho.whoitemeq) {
        List<L1ItemInstance> items = pc.getInventory().getItems();
        List<L1ItemInstance> itemsx = new CopyOnWriteArrayList<>();
        Iterator<L1ItemInstance> iterator2 = items.iterator();
        while (iterator2.hasNext()) {
          L1ItemInstance item = iterator2.next();
          if (item.isEquipped())
            itemsx.add(item); 
        } 
        herotpc.sendPackets(new S_WhoHero(herotpc, 0, itemsx));
        String msg2 = "";
        String msg3 = "";
        String msg4 = "";
        String msg5 = "";
        String msg6 = "";
        String msg7 = "";
        String msg8 = "";
        String msg9 = "";
        String msg10 = "";
        String msg11 = "";
        String msg12 = "";
        int i = pc.getLevel();
        msg3 = String.valueOf(pc.getCurrentHp()) + " / " + pc.getMaxHp();
        msg4 = String.valueOf(pc.getCurrentMp()) + " / " + pc.getMaxMp();
        int j = pc.getAc();
        short s1 = pc.getStr();
        short s2 = pc.getDex();
        short s3 = pc.getInt();
        short s4 = pc.getCon();
        short s5 = pc.getWis();
        short s6 = pc.getCha();
        msg12 = String.valueOf(pc.getMr()) + " %";
        herotpc.sendPackets(new S_SystemMessage("\\fT等级:[" + i + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fW血量:[" + msg3 + "]  //  魔力:[" + msg4 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fU防御:[" + j + "]  //  魔防:[" + msg12 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR力量:[" + s1 + "]  //  敏捷:[" + s2 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR智力:[" + s3 + "]  //  体质:[" + s4 + "]"));
        herotpc.sendPackets(new S_SystemMessage("\\fR精神:[" + s5 + "]  //  魅力:[" + s6 + "]"));
        herotpc.sendPackets(new S_SystemMessage(
              "出生素质  力:" + pc.getOriginalStr() + " 敏:" + pc.getOriginalDex() + " 智:" + pc.getOriginalInt()));
        herotpc.sendPackets(new S_SystemMessage(
              "出生素质  精:" + pc.getOriginalWis() + " 体:" + pc.getOriginalCon() + " 魅:" + pc.getOriginalCha()));
        return;
      } 
    } 
  }
  
  public S_WhoCharinfo(L1PcInstance pc, L1PcInstance tpc) {
    this._byte = null;
    writeC(71);
    writeH(166);
    writeC(1);
    List<L1ItemInstance> items = tpc.getInventory().getItems();
    List<L1ItemInstance> itemsx = new CopyOnWriteArrayList<>();
    Iterator<L1ItemInstance> iterator = items.iterator();
    while (iterator.hasNext()) {
      L1ItemInstance item = iterator.next();
      if (pc.isGm()) {
        itemsx.add(item);
        continue;
      } 
      if (!item.isEquipped())
        continue; 
      itemsx.add(item);
    } 
    pc.sendPackets(new S_WhoXljnet(pc, 0, itemsx));
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
